package com.jsmile.cloud.authc.sys.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jsmile.cloud.authc.api.res.ResSysUser;
import com.jsmile.cloud.authc.sys.model.SysUser;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2019年11月01日 08:15:30
 */
@Mapper
public interface SysUserDao extends BaseMapper<SysUser> {

    @Select("SELECT a.*,b.dept_name deptName FROM t_op_sys_user a left join t_op_sys_department b on a.dept_id=b.id where "
        + "a.tenant_id=#{tenantId} AND a.user_type=#{userType} AND  a.del_flag=#{delFlag} AND (a.user_name=#{username} or a.email=#{username} or a.phone=#{username}) limit 1")
    ResSysUser findByUsername(@Param("username") String username, @Param("tenantId") Long tenantId, @Param("userType") Integer userType, @Param("delFlag") Integer delFlag);

    @Select("SELECT a.*,b.dept_name deptName FROM t_op_sys_user a left join t_op_sys_department b on a.dept_id=b.id where "
        + "a.tenant_id=#{tenantId} and a.shop_id=#{shopId} AND a.user_type=#{userType} AND  a.del_flag=#{delFlag} AND (a.user_name=#{username} or a.email=#{username} or a.phone=#{username}) limit 1")
    ResSysUser findByUsernameAndShopId(@Param("username") String username, @Param("tenantId") Long tenantId, @Param("shopId") Long shopId, @Param("userType") Integer userType,
        @Param("delFlag") Integer delFlag);
}
